//
//  HTMainViewController.swift
//  weibo
//
//  Created by JonsonLiu on 2017/2/22.
//  Copyright © 2017年 JonsonLiu. All rights reserved.
//

import UIKit


class HTMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //定义闭包
        let composeButtonClick = {
            print("打印了")
        }
        
        
        //可以使用kvc模式来获取tabbar  来重写,tababr 不能获取到,其实是私有的
        let tabBar = HTTabbar()
        self.setValue(tabBar, forKey: "tabBar")
        tabBar.composeButtonClick = composeButtonClick
        
        

        addChildViewController(vc: HTHomeTableViewController(), imageName:"tabbar_home" , title: "首页")
        addChildViewController(vc: HTDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(vc: HTMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(vc: HTProfileTableViewController(), imageName: "tabbar_profile", title: "我的")
    }
    
    private func addChildViewController(vc: UIViewController,imageName:String
        ,title:String) {
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named:imageName)
        vc.tabBarItem.selectedImage = UIImage(named:"\(imageName)_selected")?.withRenderingMode(.alwaysOriginal)
        //设置字体颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        addChildViewController(UINavigationController(rootViewController:vc))
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
